home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / PowerPC / Dev / PPCRelease / Examples / Library / Libs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-10  |  6.7 KB  |  282 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <powerup/gcclib/powerup_protos.h>
  6. #include <powerup/ppclib/object.h>
  7. //#include <stdio.h>
  8.  
  9. #define    Add(a,b)                            \
  10. ({                                    \
  11.     if (!AddFuncPtr)                        \
  12.     {                                \
  13.         if (!(AddFuncPtr=PPCGetLibSymbol(LibObject,"Add")))    \
  14.         {                            \
  15.             /*PPCAlert(0x87000000);*/            \
  16.         }                            \
  17.     }                                \
  18.     (*AddFuncPtr)(##a,##b);                        \
  19. })
  20.  
  21. #define    Sub(a,b)                            \
  22. ({                                    \
  23.     if (!SubFuncPtr)                        \
  24.     {                                \
  25.         if (!(SubFuncPtr=PPCGetLibSymbol(LibObject,"Sub")))    \
  26.         {                            \
  27.             /*PPCAlert(0x87000000);*/            \
  28.         }                            \
  29.     }                                \
  30.     (*SubFuncPtr)(##a,##b);                        \
  31. })
  32.  
  33. /*
  34.  * This uses a macro varargs extension to gcc
  35.  * The only wait to pass ... to ... functions.
  36.  */
  37.  
  38.  
  39. #define    Print(a,b...)                            \
  40. ({                                    \
  41.     if (!PrintFuncPtr)                        \
  42.     {                                \
  43.         if (!(PrintFuncPtr=PPCGetLibSymbol(LibObject,"Print")))    \
  44.         {                            \
  45.             /*PPCAlert(0x87000000);*/            \
  46.         }                            \
  47.     }                                \
  48.     (*PrintFuncPtr)(##a,##b);                    \
  49. })
  50.  
  51.  
  52. int        (*AddFuncPtr)(int,int);
  53. int        (*SubFuncPtr)(int,int);
  54. int        (*PrintFuncPtr)(const char*,...);
  55.  
  56. int    main(void)
  57. {
  58. void        *LibObject;
  59. struct TagItem    Tags[5];
  60. int        (*AddFunc)(int,int);
  61. int        (*SubFunc)(int,int);
  62. int        Result;
  63. ULONG        *Version;
  64. ULONG        *Revision;
  65.  
  66.   Result        =    0;
  67.   Tags[0].ti_Tag    =    TAG_END;
  68.  
  69.   if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
  70.                                Tags))
  71.   {
  72.     PPCprintf("opened lib without version or revision\n");
  73.     AddFunc    =(int    (*)(int,int))    PPCGetLibSymbol(LibObject,
  74.                                                         "Add");
  75.     SubFunc    =(int    (*)(int,int))    PPCGetLibSymbol(LibObject,
  76.                                                         "Sub");
  77.  
  78.     Version    =(ULONG*) PPCGetLibSymbol(LibObject,
  79.                                           "__LIB_Version");
  80.     Revision    =(ULONG*) PPCGetLibSymbol(LibObject,
  81.                                           "__LIB_Revision");
  82.     if (Version || Revision)
  83.     {
  84.       PPCprintf("Library Version %ld.%ld\n",
  85.                 *Version,
  86.                 *Revision);
  87.     }
  88.  
  89.     if (AddFunc)
  90.     {
  91.       Result=(*AddFunc)(10,30);
  92.       Result=(*SubFunc)(Result,20);
  93.  
  94.       PPCprintf("Example 10+30-20=%ld\n",
  95.                 Result);
  96.     }
  97.  
  98. //    Result={(*AddFunc)(10,30);}
  99.  
  100.     Result=Add(100,300);
  101.     Result=Sub(Result,200);
  102.  
  103.     Print("Example %ld+%ld-%ld=%ld\n",
  104.           100,
  105.           300,
  106.           200,
  107.           Result);
  108.  
  109.     PPCCloseLibrary(LibObject);
  110.   }
  111.   else
  112.   {
  113.     PPCprintf("failed to open lib without version or revision\n");
  114.   }
  115.  
  116.   Tags[0].ti_Tag    =    PPCELFLOADTAG_LIBVERSION;
  117.   Tags[0].ti_Data    =    30;
  118.   Tags[1].ti_Tag    =    TAG_END;
  119.  
  120.   if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
  121.                                Tags))
  122.   {
  123.     PPCprintf("opened lib with version 30\n");
  124.     PPCCloseLibrary(LibObject);
  125.   }
  126.   else
  127.   {
  128.     PPCprintf("failed to open lib with version 30\n");
  129.   }
  130.  
  131.   Tags[0].ti_Tag    =    PPCELFLOADTAG_LIBVERSION;
  132.   Tags[0].ti_Data    =    50;
  133.   Tags[1].ti_Tag    =    TAG_END;
  134.  
  135.   if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
  136.                                Tags))
  137.   {
  138.     PPCprintf("opened lib with version 50\n");
  139.     PPCCloseLibrary(LibObject);
  140.   }
  141.   else
  142.   {
  143.     PPCprintf("failed to open lib with version 50\n");
  144.   }
  145.  
  146.   Tags[0].ti_Tag    =    PPCELFLOADTAG_LIBVERSION;
  147.   Tags[0].ti_Data    =    30;
  148.   Tags[1].ti_Tag    =    PPCELFLOADTAG_LIBREVISION;
  149.   Tags[1].ti_Data    =    650;
  150.   Tags[2].ti_Tag    =    TAG_END;
  151.  
  152.   if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
  153.                                Tags))
  154.   {
  155.     PPCprintf("opened lib with version 30 revision 650\n");
  156.     PPCCloseLibrary(LibObject);
  157.   }
  158.   else
  159.   {
  160.     PPCprintf("failed to open lib with version 30 revision 650\n");
  161.   }
  162.  
  163.   Tags[0].ti_Tag    =    PPCELFLOADTAG_LIBVERSION;
  164.   Tags[0].ti_Data    =    41;
  165.   Tags[1].ti_Tag    =    PPCELFLOADTAG_LIBREVISION;
  166.   Tags[1].ti_Data    =    667;
  167.   Tags[2].ti_Tag    =    TAG_END;
  168.  
  169.   if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
  170.                                Tags))
  171.   {
  172.     PPCprintf("opened lib with version 41 revision 667\n");
  173.     PPCCloseLibrary(LibObject);
  174.   }
  175.   else
  176.   {
  177.     PPCprintf("failed to open lib with version 41 revision 667\n");
  178.   }
  179.  
  180.   Tags[0].ti_Tag    =    PPCELFLOADTAG_LIBVERSION;
  181.   Tags[0].ti_Data    =    42;
  182.   Tags[1].ti_Tag    =    PPCELFLOADTAG_LIBREVISION;
  183.   Tags[1].ti_Data    =    666;
  184.   Tags[2].ti_Tag    =    TAG_END;
  185.  
  186.   if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
  187.                                Tags))
  188.   {
  189.     PPCprintf("opened lib with version 42 revision 666\n");
  190.     PPCCloseLibrary(LibObject);
  191.   }
  192.   else
  193.   {
  194.     PPCprintf("failed to open lib with version 42 revision 666\n");
  195.   }
  196.  
  197.  
  198.   Tags[0].ti_Tag    =    PPCELFLOADTAG_LIBVERSION;
  199.   Tags[0].ti_Data    =    42;
  200.   Tags[1].ti_Tag    =    PPCELFLOADTAG_LIBREVISION;
  201.   Tags[1].ti_Data    =    667;
  202.   Tags[2].ti_Tag    =    TAG_END;
  203.  
  204.   if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
  205.                                Tags))
  206.   {
  207.     PPCprintf("opened lib with version 42 revision 667\n");
  208.     PPCCloseLibrary(LibObject);
  209.   }
  210.   else
  211.   {
  212.     PPCprintf("failed to open lib with version 42 revision 667\n");
  213.   }
  214.  
  215.  
  216.   Tags[0].ti_Tag    =    PPCELFLOADTAG_LIBVERSION;
  217.   Tags[0].ti_Data    =    41;
  218.   Tags[1].ti_Tag    =    PPCELFLOADTAG_LIBREVISION;
  219.   Tags[1].ti_Data    =    666;
  220.   Tags[2].ti_Tag    =    PPCELFLOADTAG_LIBEXACTVERSION;
  221.   Tags[2].ti_Data    =    TRUE;
  222.   Tags[3].ti_Tag    =    TAG_END;
  223.  
  224.   if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
  225.                                Tags))
  226.   {
  227.     PPCprintf("opened lib with exact version 41 and revision 666\n");
  228.     PPCCloseLibrary(LibObject);
  229.   }
  230.   else
  231.   {
  232.     PPCprintf("failed to open lib with exact version 41 and revision 666\n");
  233.   }
  234.  
  235.  
  236.  
  237.   Tags[0].ti_Tag    =    PPCELFLOADTAG_LIBVERSION;
  238.   Tags[0].ti_Data    =    42;
  239.   Tags[1].ti_Tag    =    PPCELFLOADTAG_LIBREVISION;
  240.   Tags[1].ti_Data    =    665;
  241.   Tags[2].ti_Tag    =    PPCELFLOADTAG_LIBEXACTVERSION;
  242.   Tags[2].ti_Data    =    TRUE;
  243.   Tags[3].ti_Tag    =    PPCELFLOADTAG_LIBEXACTREVISION;
  244.   Tags[3].ti_Data    =    TRUE;
  245.   Tags[4].ti_Tag    =    TAG_END;
  246.  
  247.   if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
  248.                                Tags))
  249.   {
  250.     PPCprintf("opened lib with exact version 42 and exact revision 665\n");
  251.     PPCCloseLibrary(LibObject);
  252.   }
  253.   else
  254.   {
  255.     PPCprintf("failed to open lib with exact version 42 and exact revision 665\n");
  256.   }
  257.  
  258.  
  259.   Tags[0].ti_Tag    =    PPCELFLOADTAG_LIBVERSION;
  260.   Tags[0].ti_Data    =    42;
  261.   Tags[1].ti_Tag    =    PPCELFLOADTAG_LIBREVISION;
  262.   Tags[1].ti_Data    =    666;
  263.   Tags[2].ti_Tag    =    PPCELFLOADTAG_LIBEXACTVERSION;
  264.   Tags[2].ti_Data    =    TRUE;
  265.   Tags[3].ti_Tag    =    PPCELFLOADTAG_LIBEXACTREVISION;
  266.   Tags[3].ti_Data    =    TRUE;
  267.   Tags[4].ti_Tag    =    TAG_END;
  268.  
  269.   if (LibObject=PPCOpenLibrary("progdir:LibsModule.elf",
  270.                                Tags))
  271.   {
  272.     PPCprintf("opened lib with exact version 42 and exact revision 666\n");
  273.     PPCCloseLibrary(LibObject);
  274.   }
  275.   else
  276.   {
  277.     PPCprintf("failed to open lib with exact version 42 and exact revision 666\n");
  278.   }
  279.  
  280.   return(0);
  281. }
  282.